import dt from '@dt/dt'
import ruleOpt from '@/biz/option/rule.js'
import toolMgr from '@/biz/base/tool.js'

let _this = null

function floorPic(info) {
  let api = toolMgr.unloadFile()
  let files = []
  if (info.imageUrls && info.imageUrls.length > 0) {
    info.imageUrls.forEach((item, index) => {
      if (item) {
        files.push({
          name: item.name || `name${index}`,
          url: item.url,
        })
      }
    })
  }
  return {
    title: '小结附件',
    key: 'imageUrls',
    uploadImg: {
      title: '小结附件',
      api,
      files,
      multiple: true,
      drag: true,
      preview: (file) => {
        console.log(file)
        toolMgr.downloadFile(file.url, file.name)
      },
      show: false,
      hideDel: false,
      maxlength: 9,
      format: ['jpg', 'jpeg', 'png'],
      formatErr: () => {
        _this.$Message.error('只支持上传jpg、jpeg、png图片！')
      },
    },
    data: {
      to: (v) => {
        let imageUrls = v.map(item => {
          return {
            name: item.name,
            url: item.response ? item.response.data.imageURL : item.url,
          }
        })
        return {
          imageUrls
        }
      }
    }
  }
}

function options(vm) {
  _this = vm
  let arr = [
  {
    title: '小结内容',
    placeholder: '请填写案场小结内容',
    key: 'content',
    input: {
      autosize: { minRows: 10 },
      maxlength: 1000,
      type: 'textarea',
      showWordLimit: true,
      change: (val) => {
        return _this.summaryChange(val)
      }
    },
    rules: [{
      required: true,
      message: '小结内容不能为空',
      trigger: 'blur'
    }]
  }, floorPic(_this.info)]
  return arr
}

export default {
  options
}